﻿using System;
using System.Collections.Generic;
using System.Text;
using StockTrader.DAL.IDAL.HnxInfo.Oracle;
using StockTrader.BusinessService.DataContract.HnxInfo;
using StockTrader.DAL.IDAL.HnxInfo;
using StockTrader.DAL.IDAL.Global;
using StockTrader.BusinessService.DataContract.Global;
using QuoteCenter.Config;

namespace StockTrader.QuoteCenter.Streamer.DAL
{
    public class DALclient
    {
        private IOHnxOrders dalOHnxOrder;

        private IHnxOrders dalHnxOrder;
        private IOHnxMarket dalOHnxMarket;
        private IHnxMarket dalHnxMarket;
        private IOHnxTopPrice dalOHnxTopPrice;
        private IHnxTopPrice dalHnxTopPrice;
        private IOHnxStock dalOHnxStock;
        private IHnxStock dalHnxStock;
        private IHnxTask dalHnxTask;
        private IHnxLe dalHnxLe;
        private IStocksInfo dalStockInfo;

        #region IOHnxOrder Members

        public List<HnxOrdersData> getOHnxAllOrders()
        {
            dalOHnxOrder = StockTrader.DAL.Factory.HnxInfo.Oracle.OHnxOrdersFactory.Create(Settings.DAL_ORAC);
            try
            {
                dalOHnxOrder.Open(Settings.CNN_HNX_ORACLE);
                return dalOHnxOrder.getOHnxAllOrders();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOHnxOrder.Close();
            }
        }

        public List<HnxOrdersData> getOHnxLastOrders(string time)
        {
            dalOHnxOrder = StockTrader.DAL.Factory.HnxInfo.Oracle.OHnxOrdersFactory.Create(Settings.DAL_ORAC);
            try
            {
                dalOHnxOrder.Open(Settings.CNN_HNX_ORACLE);
                return dalOHnxOrder.getOHnxLastOrders(time);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOHnxOrder.Close();
            }
        }

        public int countOHnxOrders()
        {
            dalOHnxOrder = StockTrader.DAL.Factory.HnxInfo.Oracle.OHnxOrdersFactory.Create(Settings.DAL_ORAC);
            try
            {
                dalOHnxOrder.Open(Settings.CNN_HNX_ORACLE);
                return dalOHnxOrder.countOHnxOrders();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOHnxOrder.Close();
            }
        }

        #endregion

        #region IHnxOrder Members

        public List<HnxOrdersData> getHnxNewOrders(decimal timeStamp)
        {
            throw new NotImplementedException();
        }

        public List<HnxOrdersData> getHnxAllOrders()
        {
            dalHnxOrder = StockTrader.DAL.Factory.HnxInfo.HnxOrdersFactory.Create(Settings.DAL_MYSQL);
            try
            {
                dalHnxOrder.Open(Settings.CNN_HNX_MYSQL);
                return dalHnxOrder.getHnxAllOrders();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHnxOrder.Close();
            }
        }

        public void deleteHnxOrders()
        {
            throw new NotImplementedException();
        }

        public void insertHnxNewOrder(HnxOrdersData order)
        {
            dalHnxOrder = StockTrader.DAL.Factory.HnxInfo.HnxOrdersFactory.Create(Settings.DAL_MYSQL);
            try
            {
                dalHnxOrder.Open(Settings.CNN_HNX_MYSQL);
                dalHnxOrder.insertHnxNewOrder(order);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHnxOrder.Close();
            }
        }

        #endregion

        #region IHnxMarket Members

        public void Open(string connString)
        {
            throw new NotImplementedException();
        }

        public void Close()
        {
            throw new NotImplementedException();
        }

        public List<HnxMarketData> getHnxNewMarketInfo(decimal timeStamp)
        {
            throw new NotImplementedException();
        }

        public List<HnxMarketData> getHnxAllMarketInfo()
        {
            throw new NotImplementedException();
        }

        public List<HnxMarketData> countHnxMarketInfo()
        {
            throw new NotImplementedException();
        }

        public void deleteHnxMarketInfo()
        {
            throw new NotImplementedException();
        }

        public void insertHnxNewMarketInfo(HnxMarketData market)
        {
            dalHnxMarket = StockTrader.DAL.Factory.HnxInfo.HnxMarketFactory.Create(Settings.DAL_MYSQL);
            try
            {
                dalHnxMarket.Open(Settings.CNN_HNX_MYSQL);
                dalHnxMarket.insertHnxNewMarketInfo(market);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHnxMarket.Close();
            }
        }

        #endregion

        #region IOHnxMarket Members


        public HnxMarketData getOHnxAllMarketInfo()
        {
            dalOHnxMarket = StockTrader.DAL.Factory.HnxInfo.Oracle.OHnxMarketFactory.Create(Settings.DAL_ORAC);
            try
            {
                dalOHnxMarket.Open(Settings.CNN_HNX_ORACLE);
                return dalOHnxMarket.getOHnxAllMarketInfo();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOHnxMarket.Close();
            }
        }

        public int countOHnxMarketInfo()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IOHnxTopPrice Members


        public List<HnxTopPriceData> getOHnxAllTopPrice()
        {
            dalOHnxTopPrice = StockTrader.DAL.Factory.HnxInfo.Oracle.OHnxTopPriceFactory.Create(Settings.DAL_ORAC);
            try
            {
                dalOHnxTopPrice.Open(Settings.CNN_HNX_ORACLE);
                return dalOHnxTopPrice.getOHnxAllTopPrice();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOHnxTopPrice.Close();
            }
        }

        public int countOHnxTopPrice()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IHnxTopPrice Members


        public List<HnxTopPriceData> getHnxNewTopPrice(decimal timeStamp)
        {
            throw new NotImplementedException();
        }

        public List<HnxTopPriceData> getHnxAllTopPrice()
        {
            throw new NotImplementedException();
        }

        public List<HnxTopPriceData> countHnxTopPrice()
        {
            throw new NotImplementedException();
        }

        public void deleteHnxTopPrice()
        {
            throw new NotImplementedException();
        }

        public void insertHnxNewTopPrice(HnxTopPriceData price)
        {
            dalHnxTopPrice = StockTrader.DAL.Factory.HnxInfo.HnxTopPriceFactory.Create(Settings.DAL_MYSQL);
            try
            {
                dalHnxTopPrice.Open(Settings.CNN_HNX_MYSQL);
                dalHnxTopPrice.insertHnxNewTopPrice(price);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHnxTopPrice.Close();
            }
        }

        #endregion

        #region IOHnxStock Members


        public List<HnxStockData> getOHnxAllStockInfo()
        {
            dalOHnxStock = StockTrader.DAL.Factory.HnxInfo.Oracle.OHnxStockFactory.Create(Settings.DAL_ORAC);
            try
            {
                dalOHnxStock.Open(Settings.CNN_HNX_ORACLE);
                return dalOHnxStock.getOHnxAllStockInfo();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalOHnxStock.Close();
            }
        }

        public int countOHnxStockInfo()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IHnxStock Members


        public List<HnxStockData> getHnxNewStockInfo(decimal timeStamp)
        {
            throw new NotImplementedException();
        }

        public List<HnxStockData> getHnxAllStockInfo()
        {
            throw new NotImplementedException();
        }

        public List<HnxStockData> countHnxStockInfo()
        {
            throw new NotImplementedException();
        }

        public void deleteHnxStockInfo()
        {
            throw new NotImplementedException();
        }

        public void insertHnxNewStockInfo(HnxStockData stock)
        {
            dalHnxStock = StockTrader.DAL.Factory.HnxInfo.HnxStockFactory.Create(Settings.DAL_MYSQL);
            try
            {
                dalHnxStock.Open(Settings.CNN_HNX_MYSQL);
                dalHnxStock.insertHnxNewStockInfo(stock);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHnxStock.Close();
            }
        }

        #endregion

        #region IHnxTask Members


        public void ClearAll()
        {
            dalHnxTask = StockTrader.DAL.Factory.HnxInfo.HnxTaskFactory.Create(Settings.DAL_MYSQL);
            try
            {
                dalHnxTask.Open(Settings.CNN_HNX_MYSQL);
                dalHnxTask.ClearAll();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHnxTask.Close();
            }
        }

        public void Backup()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IHnxLe Members

        public List<HnxLeData> getHnxAllLe(int stockId)
        {
            throw new NotImplementedException();
        }

        public void deleteHnxLe()
        {
            throw new NotImplementedException();
        }

        public void insertHnxNewLe(HnxStockData le)
        {
            dalHnxLe = StockTrader.DAL.Factory.HnxInfo.HnxLeFactory.Create(Settings.DAL_MYSQL);
            try
            {
                dalHnxLe.Open(Settings.CNN_HNX_MYSQL);
                dalHnxLe.insertHnxNewLe(le);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalHnxLe.Close();
            }
        }

        #endregion

        public void insertNewStocksInfo(StocksInfoData stock)
        {
            dalStockInfo = StockTrader.DAL.Factory.Global.StocksInfoFactory.Create(Settings.DAL_MYSQL);
            try
            {
                dalStockInfo.Open(Settings.CNN_HNX_MYSQL);
                dalStockInfo.insertStocksInfo(stock);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dalStockInfo.Close();
            }
        }
    }
}
